var name = "somoveLanguage";
var langMsg;

function setCookie(name, value) {
    var Days = 30;
    var exp = new Date(); //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
//获取cookies
function getCookie(name){  
    var arr = document.cookie.match(new RegExp("(^| )" + name + "=([^;]*)(;|$)"));
    if (arr != null) return unescape(arr[2]);
    return "zh"
}
$(function() {
     //根据cookie选择语言
    if (getCookie(name) != "") {
        if (getCookie(name) == "zh") {
        	$('.changeLangBtn').attr('isopen','true').css('left','53px');
            $("[data-localize]").localize("lang", {
			    pathPrefix: "lang",
			    language: "zh"
			});
            console.log("come in cookie zh");
        }
        if (getCookie(name) == "en") {
        	$('.changeLangBtn').attr('isopen','false').css('left','3px');
            $("[data-localize]").localize("lang", {
			    pathPrefix: "lang",
			    language: "en"
			});
            console.log("come in cookie en");
        }
        $.ajaxSettings.async = false;
        $.getJSON("lang/lang-"+getCookie(name)+".json", function (data){
            langMsg=data;
        });
        $.ajaxSettings.async = true;
    }
    //切换按钮
    $('.changeLangBtn').on('click',function(){
	    if ($(this).attr('isopen') == 'false') {
	        $(this).attr('isopen','true');
	        var value = "zh";
		    setCookie(name, value);
		    console.log("change Lang" + name + value);
		    location.reload();
	    } else {
	        $(this).attr('isopen','false');
	        var value = "en";
		    setCookie(name, value);
		    console.log("change Lang" + name + value);
		    location.reload();
	    }
	});
});
